
local S = mobs.intllib

mobs:register_mob("mobs_monster:desert_demon", {
	type = "monster",
	knock_back = false,
	passive = false,
	attack_type = "dogshoot",
	dogshoot_switch = 1,
	dogshoot_count_max = 50,
	dogshoot_count2_max = 15,
	shoot_interval = 1.5,
	shoot_offset = 2,
	arrow = "mobs_monster:desert_demon_arrow",
	pathfinding = true,
	reach = 1.5,
	damage = 8,
	hp_min = 180,
	hp_max = 180,
	armor = 20,
	collisionbox = {-0.4, -1, -0.4, 0.4, 0.8, 0.4},
	visual = "mesh",
	mesh = "mobs_sand_monster.b3d",
	textures = {
		{"mobs_desert_demon.png"},
	},
	blood_texture = "mobs_blacksand_particles.png",
	makes_footstep_sound = true,
	sounds = {
		random = "mobs_sandmonster",
		shoot_attack = "mobs_desertdemon_shoot",
		distance = 25,
	},
	walk_velocity = 1.5,
	run_velocity = 2,
	view_range = 25,
	jump = true,
	floats = 0,
	drops = {
		{name = "default:desert_sand", chance = 1, min = 1, max = 3},
		{name = "default:desert_sand", chance = 1, min = 1, max = 3},
		{name = "default:desert_sand", chance = 1, min = 1, max = 3},
		{name = "default:desert_sand", chance = 1, min = 1, max = 3},	
		{name = "default:desert_sand", chance = 1, min = 1, max = 3},
		{name = "default:desert_sand", chance = 1, min = 1, max = 3},
		{name = "default:desert_sand", chance = 1, min = 1, max = 3},
		{name = "default:desert_sand", chance = 2, min = 1, max = 3},
		{name = "mobs_monster:sand_monster", chance = 1, min = 1, max = 1},
		{name = "mobs_monster:sand_monster", chance = 2, min = 1, max = 1},
		
	},
	water_damage = 0,
	lava_damage = 10,
	light_damage = -3,
	fear_height = 4,
	animation = {
		speed_normal = 15,
		speed_run = 15,
		stand_start = 0,
		stand_end = 39,
		walk_start = 41,
		walk_end = 72,
		run_start = 74,
		run_end = 105,
		punch_start = 74,
		punch_end = 105,
		shoot_start = 74,
		shoot_end = 105,
	},
	immune_to = {
		{"mobs:assassinblade", 5},
		{"default:shovel_bronze", 1},
		{"default:shovel_steel", 1},
		{"default:shovel_mese", 2},
		{"default:shovel_diamond", 2},
		{"ethereal:shovel_crystal", 2},
		{"nether:shovel_nether", 3},
		{"all", 0},
	},
	
	do_custom = function(self, dtime)
	
		local pos = self.object:get_pos()
	
			-- timer (15 seconds)
			self.desert_demon_timer = (self.desert_demon_timer or 0) + dtime
				if self.desert_demon_timer < 15 then
			return
		end
		
			-- +20 max health and +2 damage every 15 seconds
			if self.hp_max < 400 then -- stops when max_health reaches 400 
				self.hp_max = self.hp_max + 20
				self.damage = self.damage + 2
			end
			
		-- spawn 1-3 sand monsters every 15 seconds
		local num = math.random(1, 3)
			for i = 1, num do
				minetest.add_entity({x=pos.x + math.random(-2, 2), y=pos.y + 1, z=pos.z + math.random(-2, 2)}, "mobs_monster:sand_monster")
		end
		
		-- reset timer
		self.desert_demon_timer = 0
	end,
	
	-- spawn 3-5 sand monsters after death
	on_die = function(self, pos)
	
		local num = math.random(3, 5)
		for i = 1, num do
        	minetest.add_entity({x=pos.x + math.random(-4, 4), y=pos.y + 1, z=pos.z + (math.random(-4, 4))}, "mobs_monster:sand_monster")
	   end
   end,
})



if not mobs.custom_spawn_monster then
mobs:spawn({
	name = "mobs_monster:desert_demon",
	nodes = {"default:desert_sand", "default:sandstone"},
	chance = 40000,
	active_object_count = 1,
	min_height = -31000,
	max_light = 7,
})
end


mobs:register_egg("mobs_monster:desert_demon", S("Desert Demon"), "default_desert_sand.png", 1)


mobs:alias_mob("mobs:desert_demon", "mobs_monster:desert_demon")


mobs:register_arrow("mobs_monster:desert_demon_arrow", {
	visual = "sprite",
	visual_size = {x = 1, y = 1},
	textures = {"mobs_desert_demon_arrow.png"},
	collisionbox = {-0.1, -0.1, -0.1, 0.1, 0.1, 0.1},
	velocity = 12,
	glow = 5,
	expire = 0.1,
	
	hit_player = function(self, player)			
			player:punch(self.object, 1.0, {
				full_punch_interval = 1.0,
				damage_groups = {fleshy = 15},
		}, nil)
	end,

		hit_mob = function(self, player)
			local pos = self.object:get_pos()
			
			-- chance to spawn a sand monster on hit_mob and heal the mob
			local num = math.random(-3, 1)
			
			minetest.sound_play("mobs_stonemonster_damage",
				{pos = pos, max_hear_distance = 15, gain = 1.5}, true)
					
			for i = 1, num do
				minetest.add_entity(pos, "mobs_monster:sand_monster")
			end
	
		player:punch(self.object, 1.0, {
			full_punch_interval = 1.0,
			damage_groups = {fleshy = -30},
		}, nil)
	end,
	
		hit_node = function(self, pos, node)
			mobs:effect(pos, 20, "mobs_blacksand_particles.png", 3, 5, 2, 0.5, nil, false)
			
			minetest.sound_play("mobs_stonemonster_damage",
				{pos = pos, max_hear_distance = 15, gain = 1.5}, true)
					
			minetest.set_node(pos, {name = "air"})
	end
})



-- Sand Monster by PilzAdam

mobs:register_mob("mobs_monster:sand_monster", {
	type = "monster",
	attack_type = "dogfight",
	passive = false,
	pathfinding = true,
	knock_back = false,
	reach = 1.5,
	damage = 14,
	hp_min = 20,
	hp_max = 40,
	armor = 80,
	collisionbox = {-0.4, -1, -0.4, 0.4, 0.8, 0.4},
	visual = "mesh",
	mesh = "mobs_sand_monster.b3d",
	textures = {
		{"mobs_sand_monster.png"},
	},
	blood_texture = "default_desert_sand.png",
	makes_footstep_sound = true,
	sounds = {
		random = "mobs_sandmonster",
	},
	walk_velocity = 1.5,
	run_velocity = 3.5,
	view_range = 25,
	jump = true,
	floats = 0,
	drops = {
		{name = "default:desert_sand", chance = 1, min = 1, max = 3},
		{name = "default:desert_sand", chance = 1, min = 1, max = 3},
		{name = "default:desert_sand", chance = 1, min = 1, max = 3},
		{name = "default:desert_sand", chance = 1, min = 1, max = 3},
		{name = "default:desert_sand", chance = 1, min = 1, max = 3},
		{name = "default:desert_sand", chance = 1, min = 1, max = 3},
		{name = "default:desert_sand", chance = 2, min = 1, max = 3},
		{name = "default:desert_sand", chance = 2, min = 1, max = 3},
	},
	water_damage = 0,
	lava_damage = 50,
	light_damage = -3,
	fear_height = 4,
	animation = {
		speed_normal = 15,
		speed_run = 15,
		stand_start = 0,
		stand_end = 39,
		walk_start = 41,
		walk_end = 72,
		run_start = 74,
		run_end = 105,
		punch_start = 74,
		punch_end = 105,
	},
	immune_to = {
		{"default:shovel_wood", 1},
		{"default:shovel_stone", 2},
		{"default:shovel_bronze", 12},
		{"default:shovel_steel", 3},
		{"default:shovel_mese", 4},
		{"default:shovel_diamond", 4},
		{"ethereal:shovel_crystal", 5},
		{"nether:shovel_nether", 5},
	},
})


if not mobs.custom_spawn_monster then
mobs:spawn({
	name = "mobs_monster:sand_monster",
	nodes = {"default:desert_sand", "default:sandstone"},
	chance = 8000,
	active_object_count = 3,
	min_height = -10000,
})
end


mobs:register_egg("mobs_monster:sand_monster", S("Sand Monster"), "default_desert_sand.png", 1)


mobs:alias_mob("mobs:sand_monster", "mobs_monster:sand_monster")